home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / GRAPHICS.SWG / 0109_Fire Graphic.pas < prev    next >
Pascal/Delphi Source File  |  1994-08-24  |  4KB  |  131 lines

  1. {
  2. Here is a little something for all you pyromaniacs, and demo coders out there.
  3.  
  4. I got my hands on Jare's fire code and thought it was pretty cool, so I made
  5. my own fire program. Although it didn't turn out like I thought it would (like
  6. Jare's) what I have is (at least I think so) something that looks more
  7. realistic.
  8.  
  9. This program was completely written by myself and was inspired by Jare's fire
  10. code (available on Internet FTP at ftp.eng.ufl.edu  pub/msdos/demos/programming
  11. /source). A 386 computer is required (Double Word copies are used), but a 486
  12. is highly recommended, as 28800 pixels are calculated each frame (I use
  13. standard mode 13h). The entire source is Pascal/Inline asm and was written
  14. using Turbo Pascal v6.0.    I hope you like it.
  15.  
  16.  
  17. { **** Program starts here ******** }
  18.  
  19. Program Phire;
  20. {$G+}    { Enable 286 instructions }
  21. { coded by Phred  7/23/94     aka Alex Chalfin    }
  22. {               Internet: achalfin@uceng.uc.edu   }
  23. { A fast computer is HIGHLY recommended.          }
  24. { Inspired by Jare's fire code                    }
  25.  
  26. Var
  27.   Screen : Array[0..63999] of Byte ABSOLUTE $A000:$0000; { the VGA screen }
  28.   VScreen : Array[0..63999] of Byte;                { an offscreen buffer }
  29.   Lookup : Array[0..199] of Word;    { an Offset lookup table }
  30.  
  31. Procedure SetPalette; Near;
  32. { Sets the Palette }
  33.  
  34. Var
  35.   p : Array[0..767] of Byte;
  36.   x : integer;
  37.  
  38. Begin
  39.   for x := 0 to 255 do            { Generate fade from orange to black }
  40.     Begin
  41.       p[x*3] := (x * 63) Shr 8;
  42.       P[x*3+1] := (x * 22) Shr 8;
  43.       P[x*3+2] := 0;
  44.     End;
  45.   Port[$3C8] := 0;
  46.   For x := 0 to 255 do        { Set the palette }
  47.     Begin
  48.       Port[$3C9] := P[x*3];
  49.       Port[$3C9] := P[x*3+1];
  50.       Port[$3C9] := P[x*3+2];
  51.     End;
  52. End;
  53.  
  54. Procedure Burnin_Down_The_House;
  55.  
  56. Var
  57.   c : Integer;
  58.  
  59. Begin
  60.   Randomize;
  61.   Repeat
  62.     For c := 0 to 319 do    { Setup bottom line "hot spots" }
  63.       If Random(4) = 1
  64.         Then VScreen[LookUp[199] + c] := Random(3) * 255;
  65.     Asm
  66.       MOV  CX,28800         { Number of pixels to calculate }
  67.       PUSH CX               { Store count on stack }
  68.       MOV  AX,Offset VScreen
  69.       PUSH AX               { Store value on stack }
  70.       MOV  SI,AX
  71.       MOV  BX,199
  72.       SHL  BX,1
  73.       MOV  AX,Word Ptr [LookUp + BX]
  74.       ADD  SI,AX
  75.       DEC  SI            { DS:SI := VScreen[LookUp[198]+319] }
  76.      @Looper:
  77.       XOR  AX,AX
  78.       XOR  BX,BX
  79.       MOV  AL,DS:[SI+319]
  80.       ADD  BX,AX
  81.       MOV  AL,DS:[SI+320]
  82.       ADD  BX,AX
  83.       MOV  AL,DS:[SI+321]
  84.       ADD  BX,AX
  85.       MOV  AL,DS:[SI]
  86.       ADD  BX,AX    { Average the three pixels below and the one that its on}
  87.       SHR  BX,2     { Divide by 4 }
  88.       JZ  @Skip
  89.       DEC  BX       { Subtract 1 if value > 0 }
  90.      @Skip:
  91.       MOV  DS:[SI],BL  { Store pixel to screen }
  92.       DEC  SI          { Move to next pixel }
  93.       DEC  CX
  94.       JNZ @Looper
  95.     { Copy the screen Buffer using Double Word copies }
  96.       MOV  BX,110
  97.       SHL  BX,1
  98.       MOV  AX,Word Ptr [LookUp + BX]
  99.       MOV  DX,AX
  100.       POP  SI        { Restore starting offset of VScreen  }
  101.       MOV  AX,$A000
  102.       MOV  ES,AX     { DS:SI = starting location in buffer }
  103.       XOR  DI,DI     { ES:DI = Starting location in screen }
  104.       ADD  SI,DX
  105.       ADD  DI,DX
  106.       POP  CX        { Retrive Count off the stack }
  107.       SHR  CX,2      { divide by 4 to get # of double words.              }
  108.      db 66h          { Since TP won't allow 386 instructions, fake it.    }
  109.       REP  MOVSW     { This translates into REP MOVSD (move double words) }
  110.     End;
  111.   Until Port[$60] = 1;   { Until ESC is pressed }
  112. End;
  113.  
  114. Begin
  115.   Asm              { Initialize mode 13h VGA mode }
  116.     MOV  AX,13h
  117.     INT  10h
  118.   End;
  119.   For LookUp[0] := 1 to 199 do            { Calculate lookup table }
  120.     LookUp[LookUp[0]] := LookUp[0] * 320;
  121.   LookUp[0] := 0;
  122.   SetPalette;
  123.   FillChar(VScreen, 64000, 0);
  124.   Burnin_Down_The_House;
  125.   Asm
  126.     MOV  AX,3
  127.     INT  10h
  128.   End;
  129. End.
  130.  
  131.